package org.chenbingkang.flink;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

public class App {

    static String json="{\"dataDate\":\"2019-10-10\",\"inAppCode\":null,\"inReqId\":null,\"inMsgId\":null,\"inOrderId\":null,\"inMsgType\":null,\"inAccount\":\"123456\",\"inSubId\":null,\"inPhone\":\"18612569508\",\"inContent\":\"北京一卡通验证码为838308,您正在进行短信登录.验证码有效期为2分钟,请勿泄露.\",\"inExtend\":null,\"inRptType\":null,\"inMsgCode\":null,\"inPhoneType\":null,\"inProvince\":null,\"inCity\":null,\"inChannel\":123456,\"resChannelIsOperator\":null,\"inSign\":null,\"inContentType\":null,\"inContentDangerNum\":null,\"inFeeType\":null,\"inFeeCnt\":null,\"inType\":null,\"inIsAudit\":null,\"inPutinTime\":\"2019-10-10 11:00:00\",\"inAgingType\":null,\"inScheduleTime\":null,\"inMsgFmt\":null,\"inInsertTime\":null,\"inIsFilterTemplate\":null,\"inTemplateCode\":null,\"resMsgIdGw\":null,\"resCode\":\"1\",\"resState\":1,\"resSendTime\":\"2019-10-10 11:01:00\",\"resInsertTime\":null,\"rptCode\":\"KEYWORD\",\"rptState\":1,\"rptReceiveTime\":null,\"rptEndTime\":null,\"rptChannelTime\":\"2019-10-10 11:10:00\",\"rptInsertTime\":null,\"rptLogGwCode\":null,\"rptLogPushType\":null,\"rptLogPushAddr\":null,\"rptLogPushContent\":null,\"rptLogPushRet\":null,\"rptLogPushResult\":null,\"rptLogPushTime\":null,\"rptLogPushCnt\":null,\"rptLogInsertTime\":null}";

    public static void main(String ... args) throws Exception{
        HttpHost httpHost=new HttpHost("192.168.180.128",9200);
        RestClientBuilder builder = RestClient.builder(httpHost);
        builder.setMaxRetryTimeoutMillis(30000);
        RestHighLevelClient restHighLevelClient=new RestHighLevelClient(builder);

        for(int i=0;i<100;i++){
            BulkRequest bulkRequest=new BulkRequest();
            for(int j=0;j<2000;j++){
                IndexRequest indexRequest=new IndexRequest("sms_send_detail_index_20191010", "doc").source(json, XContentType.JSON);
                bulkRequest.add(indexRequest);
            }
            BulkResponse bulkResponse=  restHighLevelClient.bulk(bulkRequest);
            System.out.println("result==="+bulkResponse.buildFailureMessage());
        }
    }
}
